package com.xky.mybatis.controller;

import com.xky.mybatis.dao.TestMapper;
import com.xky.mybatis.domain.Test;
import com.xky.mybatis.service.Service;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author keying.xia
 * @date 2017/12/8
 */
@RestController
public class Controller {

    @Autowired
    private Service service;

    @ApiOperation(value = "获取所有用户",notes = "获取所有用户")
    @GetMapping(value = "/getAll")
    public List<Test> getAll(){
        return service.getAll();
    }

    @ApiOperation(value = "获取某个用户",notes = "获取某个用户")
    @ApiImplicitParam(name = "id",value = "用户的id",required = true,paramType = "path",dataType = "Integer")
    @GetMapping(value = "/getOne/{id}")
    public Test getOne(@PathVariable Integer id){
        return service.getOne(id);
    }

    @ApiOperation(value = "新增用户",notes = "新增用户")
    @ApiImplicitParam(name = "test",value = "用户对象",dataType = "Test",required = true)
    @PostMapping(value = "/add")
    public int add(@RequestBody Test test){
        return service.add(test);
    }

    @ApiOperation(value = "删除用户",notes = "删除用户")
    @ApiImplicitParam(name = "id",value = "用户id",dataType = "Integer",required = true,paramType = "path")
    @DeleteMapping(value = "/delete/{id}")
    public int delete(@PathVariable Integer id){
        return service.delete(id);
    }


    @ApiOperation(value = "更新用户",notes = "更新用户")
    @ApiImplicitParam(name = "id",value = "用户id",dataType = "Integer",required = true,paramType = "path")
    @PutMapping(value = "/update/{id}")
    public int update(@PathVariable Integer id, @RequestBody Test test){
        return service.update(id,test);
    }

}
